package com.zlq.cn.controller.sign.ai;

import com.alibaba.fastjson.JSONObject;
import com.aliyun.docmind_api20220711.models.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.bootstrap.SignApiBootstrap;
import com.zlq.cn.controller.BaseController;
import com.zlq.cn.entity.AsyncJob;
import com.zlq.cn.service.ai.AliyunService;
import com.zlq.cn.service.un.AsyncJobService;
import com.zlq.cn.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "AI-阿里云")
@Validated
@RestController
@RequestMapping("/ai/aliyun")
public class AiAliyunController extends BaseController {

    @Resource
    private AliyunService aliyunService;

    @Resource
    private AsyncJobService asyncJobService;

    @ApiOperation("PDF转Word异步提交服务")
    @PostMapping("/submit/convert/pdf/to/word/job")
    public SignApiResult<String> submitConvertPdfToWordJob(@RequestBody SubmitConvertPdfToWordJobRequest request) {
        aliyunService.submitConvertPdfToWordJob(request);
        return SignApiResult.resultSuccess("提交成功");
    }

    @ApiOperation("图片转Word异步提交服务")
    @PostMapping("/submit/convert/image/to/word/job")
    public SignApiResult<String> submitConvertImageToWordJob(@RequestBody SubmitConvertImageToWordJobRequest request) {
        aliyunService.submitConvertImageToWordJob(request);
        return SignApiResult.resultSuccess("提交成功");
    }

    @ApiOperation("PDF转Excel异步提交服务")
    @PostMapping("/submit/convert/pdf/to/excel/job")
    public SignApiResult<String> submitConvertPdfToExcelJob(@RequestBody SubmitConvertPdfToExcelJobRequest request) {
        aliyunService.submitConvertPdfToExcelJob(request);
        return SignApiResult.resultSuccess("提交成功");
    }

    @ApiOperation("图片转Excel异步提交服务")
    @PostMapping("/submit/convert/image/to/excel/job")
    public SignApiResult<String> submitConvertImageToExcelJob(@RequestBody SubmitConvertImageToExcelJobRequest request) {
        aliyunService.submitConvertImageToExcelJob(request);
        return SignApiResult.resultSuccess("提交成功");
    }

    @ApiOperation("PDF转图片异步提交服务")
    @PostMapping("/submit/convert/pdf/to/image/job")
    public SignApiResult<String> submitConvertPdfToImageJobAdvance(@RequestBody SubmitConvertPdfToImageJobAdvanceRequest request) {
        aliyunService.submitConvertPdfToImageJobAdvance(request);
        return SignApiResult.resultSuccess("提交成功");
    }

    @ApiOperation("图片转PDF异步提交服务")
    @PostMapping("/submit/convert/image/to/pdf/job")
    public SignApiResult<String> submitConvertImageToPdfJob(@RequestBody SubmitConvertImageToPdfJobRequest request) {
        aliyunService.submitConvertImageToPdfJob(request);
        return SignApiResult.resultSuccess("提交成功");
    }

    @ApiOperation("图片转Word异步提交历史")
    @PostMapping("/image/word/list")
    public SignApiResult<Page<AsyncJob>> imageWordList(@RequestBody AsyncJob asyncJob) {
        return SignApiResult.resultSuccess(asyncJobService.lambdaQuery()
                .eq(AsyncJob::getImei, SignApiBootstrap.requestFanYiUser().getFanyiUserImei())
                .likeRight(AsyncJob::getType, "ali_ai_")
                .eq(StringUtils.isNotBlank(asyncJob.getType()), AsyncJob::getType, asyncJob.getType())
                .orderByDesc(AsyncJob::getCreateTime)
                .page(super.<AsyncJob>getPage()));
    }
}
